package router

import (
	systemController "gitee.com/wangshh_123/cross-pay-go/src/controller/system"
	"gitee.com/wangshh_123/cross-pay-go/src/middleware"

	"github.com/gin-gonic/gin"
)

// SetupDepartmentRouter 设置部门管理路由
func SetupDepartmentRouter(api *gin.RouterGroup) {
	// 创建部门控制器实例
	departmentController := systemController.NewDepartmentController()

	// 部门管理路由组（需要管理员权限）
	departments := api.Group("/admin/departments")
	departments.Use(middleware.AuthMiddleware())
	{
		departments.GET("", middleware.PermissionMiddleware("admin:access"), departmentController.GetDepartmentList)          // 获取部门列表
		departments.POST("", middleware.PermissionMiddleware("matrix_transfer"), departmentController.CreateDepartment)       // 创建部门
		departments.PUT("/:id", middleware.PermissionMiddleware("matrix_transfer"), departmentController.UpdateDepartment)    // 更新部门
		departments.DELETE("/:id", middleware.PermissionMiddleware("matrix_transfer"), departmentController.DeleteDepartment) // 删除部门
	}

	// 部门用户关联管理路由组（需要管理员权限）
	departmentUsers := api.Group("/admin/department-users")
	departmentUsers.Use(middleware.AuthMiddleware())
	{
		departmentUsers.GET("", middleware.PermissionMiddleware("admin:access"), departmentController.GetDepartmentUserList)               // 获取部门用户列表
		departmentUsers.POST("", middleware.PermissionMiddleware("matrix_transfer"), departmentController.CreateDepartmentUser)            // 创建部门用户关联
		departmentUsers.PUT("/:id", middleware.PermissionMiddleware("matrix_transfer"), departmentController.UpdateDepartmentUser)         // 更新部门用户关联
		departmentUsers.DELETE("/:id", middleware.PermissionMiddleware("matrix_transfer"), departmentController.DeleteDepartmentUser)      // 删除部门用户关联
		departmentUsers.POST("/transfer", middleware.PermissionMiddleware("matrix_transfer"), departmentController.TransferDepartmentUser) // 用户更换部门
	}

	// 用户部门查询路由组（需要管理员权限）
	users := api.Group("/admin/users")
	users.Use(middleware.AuthMiddleware())
	{
		users.GET("/:user_id/history", middleware.PermissionMiddleware("admin:access"), departmentController.GetUserDepartmentHistory) // 获取用户部门历史
	}
}
